package okhttp3.internal.huc;

import java.io.IOException;

import okio.Buffer;
import okio.BufferedSink;
import okio.Okio;
import okio.Pipe;
import okio.Source;

/**
 * <p>Title: StreamedRequestBody </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023/11/21 16:34
 */
//final class StreamedRequestBody extends OutputStreamRequestBody implements UnrepeatableRequestBody {
final class StreamedRequestBody extends OutputStreamRequestBody {
    private final Pipe pipe = new Pipe(8192L);

    StreamedRequestBody(long expectedContentLength) {
        this.initOutputStream(Okio.buffer(this.pipe.sink()), expectedContentLength);
    }

    public void writeTo(BufferedSink sink) throws IOException {
        Source source = this.pipe.source();
        if (source == null) {
            return;
        }
        Buffer buffer = new Buffer();
        while (source.read(buffer, 8192L) != -1L) {
            sink.write(buffer, buffer.size());
        }

    }
}